package com.ch.sys.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ch.sys.model.Function;

@Service
public class FunctionService {

	/**
	 * 根据员工角色查询所属菜单
	 * @return
	 */
	@Transactional
	public List<Function> findByRole(Long roleId) {
		List<Function> parents = Function.find(roleId, 0L);
		for(Function function : parents) {
			Long pId = function.getLong(Function.ID);
			
			List<Function> childs = Function.find(roleId, pId);
			function.set("sub_menus", childs);
		}
		
		return parents;
	} 
}
